package org.jeecg.modules.simulator.factory.train.load;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import org.jeecg.modules.simulator.model.train.TrainPhysics;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/**
 * @program: gp
 * @description:
 * @author: lydms
 * @create: 2024-08-07 14:42
 **/
public class TrainPhysicsRead implements TrainPhysicsLoader{

    @Getter
    List<TrainPhysics> trainPhysicsList=new ArrayList<>();

    @Override
    public void  trainPsread(){
        String   path = "D:/aaaa/traintype.json";
        List<TrainPhysics> relist=new ArrayList<>();
        try {
            String jsonString = new String(Files.readAllBytes(Paths.get(path)));
            JSONArray jsonArray = JSON.parseArray(jsonString);
            for (int i = 0; i < jsonArray.size(); i++) {
                TrainPhysics trainPhysics = new TrainPhysics();
                JSONObject jsonObject = jsonArray.getJSONObject(i);

                String name=jsonObject.getString("name") ;
                trainPhysics.setTrainName(name);
                int capacity = jsonObject.getInteger("capacity");
                trainPhysics.setCapacity(capacity);
                int area = jsonObject.getInteger("area");
                trainPhysics.setArea(area);
                int numberOfPeopleSMeter = jsonObject.getInteger("numberOfPeopleSMeter");
                trainPhysics.setNumberOfPeopleSMeter(numberOfPeopleSMeter);
                String maxFullLoad = jsonObject.getString("maxfullload");
                trainPhysics.setMaxFullLoad(maxFullLoad);
                int maxspeed=jsonObject.getInteger("maxspeed");
                trainPhysics.setMaxSpeed(maxspeed);

                int carriagesnumber=jsonObject.getInteger("carriagesnumber");
                trainPhysics.setCarriagesNumber(carriagesnumber);

                trainPhysicsList.add(trainPhysics);


            }

        } catch (IOException e) {
            e.printStackTrace();
        }



    }
}
